<div id="user_rapoarte_facturi_emise"></div>

<script type="text/javascript">			
Ext.onReady(function(){	
		
	var ds_facturi_emise;
	var sm_facturi_emise;	
	var cm_facturi_emise;
	var grid_user_rapoarte_facturi_emise;
	var fp_w_user_rapoarte_facturi_emise_anulare;
	var w_user_rapoarte_facturi_emise_anulare;
	var fp_w_user_rapoarte_facturi_emise_istoric;
	var w_user_rapoarte_facturi_emise_istoric;
	var ds_istoric_plati;
	var cm_istoric_plati;
	var w_user_rapoarte_facturi_emise_previzualizare;
	var sm_istoric_plati;
	var w_user_functionalitati_anulare_incasare;
	var fp_w_user_functionalitati_anulare_incasare;

	htmlEditor = new Ext.form.HtmlEditor({
		id				:'id-mesaj',	
		allowBlank		:false,
		blankText		:'Reguli validare <br /><i>Camp obligatoriu</i>', 												
	    height			:190,
		fieldLabel		:'Motivul',
		name			:'motivul',	
	    anchor			:'90%',
	    enableColors	:false,
	    enableAlignments:false,
		enableFont		:false,
		enableFontSize	:false,
		enableLinks		:false,
		enableSourceEdit:false,
		fontFamilies	:['Tahoma'],
		autoMonitorDesignMode:false,
		validateValue	: function(){
			 if (this.getValue() !== ''){
                 this.clearInvalid();
                 return true; 																						 	
			 } else {
                 this.markInvalid(this.blankText);
                 return false;																						 	
			 }
		}																			
	});	
																			
	

	function facturi_cancel(){
						if (!w_user_rapoarte_facturi_emise_anulare) {
									// anulare factura form panel	-----------------------------------------------------
									//-----------------------------------------------------------------------------------	

									fp_w_user_rapoarte_facturi_emise_anulare = new Ext.FormPanel({
												id			:"add-anulare-form",
												monitorValid:true,
												labelAlign	:'top',
												bodyStyle	:'padding:5px',
										        layout		:'column',
										        border		:false,								
												items: [{
												            columnWidth:0.5,
															defaultType: 'textfield',
												            layout: 'form',
															border:false,
															items:[{
																fieldLabel: 'Id factura',
																id:'y-id-factura',
																name: 'FK_FACTURI',
																anchor: '90%',
																readOnly:true
															},{
																fieldLabel: 'Numar factura',
																id:'y-nr-factura',
																name: 'nr_factura',
																anchor: '90%',
																readOnly:true
															},{
																fieldLabel: 'Data emiterii',
																id:'y-data-emiterii',
																name: 'data_emiterii',
																anchor: '90%',
																readOnly:true
															},new Ext.form.DateField({
																id			:'y-data-anulare',	
																anchor		:'90%',
									                        	fieldLabel	:'Data',
									                        	name		:'data',
																allowBlank	:false,
																blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',	
																readOnly 	:true,
																invalidText :'{value} nu este o data valida - Formatul corect este: aaaa-ll-zz',
																blankText	:'Reguli validare <br /><i>Camp obligatoriu</i><br /><i>Format: aaaa-ll-zz</i>',
																format		:'Y-m-d'
				                    						})
															]
														},{
												            columnWidth:0.5,
															defaultType: 'textarea',
												            layout: 'form',
															border:false,
															items:[htmlEditor]								
														}],
												buttons:[{
													text:'Save and Close',
													tooltip:'Salvati si inchideti',
													formBind:true,
													handler:function(){
							        						fp_w_user_rapoarte_facturi_emise_anulare.getForm().submit({
														  		url: "user/functionalitati/anulare/" + Math.random(),
																params:{saferequest:true,table:'facturi',cyDep:false},
														  		waitTitle: 'Connecting',
														  		waitMsg: 'Validating and saving data...',
																success:function(form, action, o) {
																	if(action.result.code == 0){
																			Ext.MessageBox.alert('Atentie:', 'Eroare la adaugare');
																	}else if(action.result.code == 1){						
																			fp_w_user_rapoarte_facturi_emise_anulare.getForm().reset();
																			w_user_rapoarte_facturi_emise_anulare.hide();	
																			ds_facturi_emise.reload();														
																			Ext.MessageBox.alert('Mesaj:', 'Adaugare efectuata cu succes!');																					
																	}else if(action.result.code == 2){
																			Ext.MessageBox.alert('Eroare la adaugare:', 'Tranzactie nereusita!');
																	}else if(action.result.code == 3){
																			Ext.MessageBox.alert('Eroare la adaugare:', 'Stergere incasari aferente factura nereusita!');
																	}else if(action.result.code == 4){
																			Ext.MessageBox.alert('Eroare la adaugare:', 'Stergere articole aferente factura nereusita!');
																	}else if(action.result.code == 5){
																			Ext.MessageBox.alert('Eroare la adaugare:', 'Stergere factura nereusita!');
																	}
																},										
																
																failure: function(form, action, o){
												                            if(action.failureType == 'server'){
												                                Ext.Msg.alert('Warning', 'Cannot save to database!', obj.errors.reason);
												                            }else{
												                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
												                            }
																}									
															});								
													}
												}]		
									});						

									// end anulare factura form panel	-------------------------------------------------
									//-----------------------------------------------------------------------------------	
																		
										w_user_rapoarte_facturi_emise_anulare = new Ext.Window({
											id				:'w-user-rapoarte-facturi-emise-anulare' + Math.random(),
											title			:'Anulare factura',
											animateTarget	:'b-cancel',
											width			:610,
											height			:400,
											plain			:true,
											layout			:'fit',
											modal			:true,
											closeAction		:'hide',
											items			:fp_w_user_rapoarte_facturi_emise_anulare,
											loadMask		:{msg:'Loading...'},
											listeners		:{
												show: function(){
													var selection = grid_user_rapoarte_facturi_emise.selModel.getSelections();
													Ext.getDom('y-id-factura').value = selection[0].id;
													Ext.getDom('y-data-emiterii').value = selection[0].json.data_emiterii;
													Ext.getDom('y-nr-factura').value = selection[0].json.numar;
												}
											},								
								            buttons: [{
											    text		:'Cancel',
												tooltip		:'Renuntati',
											    handler		:function(){
													fp_w_user_rapoarte_facturi_emise_anulare.getForm().reset();
											        w_user_rapoarte_facturi_emise_anulare.hide();
											    }
											}]
									
										});								
							
						}else {}
						w_user_rapoarte_facturi_emise_anulare.show(null, htmlEditor.checkDesignMode, htmlEditor);	
					
		}

		function facturi_check_cancel(){
			if(grid_user_rapoarte_facturi_emise.selModel.getCount() == 1){
				Ext.MessageBox.confirm('Confirmation','Anulare factura. Continuati?', function(btn){
					if (btn == 'yes') {
						
						var selection = grid_user_rapoarte_facturi_emise.selModel.getSelections();
						var selectedId = selection[0].id;
													
						Ext.Ajax.request({
						   url: 'user/functionalitati/verificaIncasari/' + Math.random(),
						   disableCaching:false,
						   params:{
								saferequest	:true,
								ID			:selectedId										   	
						   },
						   success: function(response, options) {
								var data = Ext.util.JSON.decode(response.responseText);
								if (data.code == 0){
									facturi_cancel();	
								} else if (data.code > 0){
									Ext.MessageBox.confirm('Confirmation','Aceasta factura are '+ data.code +' incasari. Continuati?', function(btn){
										if (btn == 'yes') {
											facturi_cancel();												
										}
									});
								}
							},										
							failure: function(form, action, o){
			                            if(action.failureType == 'server'){
			                                Ext.Msg.alert('Warning', 'Cannot save to database!', obj.errors.reason);
			                            }else{
			                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
			                            }
							}
						});							
					}					
				});
			} else {
			  	Ext.MessageBox.alert('Warning','Pentru a anula o factura, selectati cel putin o inregistrare!');
			}
		}	

	    function rdr_modalitate(val){
	        if(val == 49){
	            return '<span style="color:green;">Cash</span>';
	        }else if(val == 50){
	            return '<span style="color:red;">Ordin de plata</span>';
	        }
	        return val;
	    }	

	    ds_istoric_plati = new Ext.data.Store({
			id			:'table_ds_istoric',	
			remoteSort	:true,	
	        proxy: new Ext.data.HttpProxy({
	            url: 'common/getTable/' + Math.random()		
	        }),
	        reader: new Ext.data.JsonReader({
	            root:'DS_INCASARI',
	            totalProperty: 'totalCount',
	            id:'ID',
	            fields: [
	                'data', 'valoarea', 'modalitate', 'nr_chit', 'data_ordin', 'nr_ordin'
	            ]
	        })
	    });	
		ds_istoric_plati.setDefaultSort('data', 'desc');
		
		sm_istoric_plati = new Ext.grid.CheckboxSelectionModel({singleSelect:true});			
					
	    cm_istoric_plati = new Ext.grid.ColumnModel([sm_istoric_plati,
				{header: "Data",dataIndex: 'data'},
				{header: "Valoare",dataIndex: 'valoarea'},
				{header: "Modalitate",dataIndex: 'modalitate',renderer:rdr_modalitate},
				{header: "Nr. chitanta",dataIndex: 'nr_chit'},
				{header: "Data OP",dataIndex: 'data_ordin'},
				{header: "Nr. OP",dataIndex: 'nr_ordin'}
		]);
		cm_istoric_plati.defaultSortable = true;
		
		grid_istoric_plati = new Ext.grid.GridPanel({
							id		:'grid_user_functionalitati_incasari',						
							ds:	ds_istoric_plati,
							cm: cm_istoric_plati,
							sm: sm_istoric_plati,
							title	:'Plati',
				            height	:260,
				            border	:true,
					        loadMask: true,
					        viewConfig: {
					            forceFit:true
					        },
							tbar:[
								{
									id		:'b-cancel',
						            text	:'Anuleaza',
						            tooltip	:'Anuleaza',
						            iconCls	:'b_delete_xml_cls',
									handler	:function(){
										if(!w_user_functionalitati_anulare_incasare){
											// fereastra anulare incasare	-----------------------------------------------------
											//-----------------------------------------------------------------------------------
											
											fp_w_user_functionalitati_anulare_incasare = new Ext.FormPanel({
														id			: "add-anulare-incasare-form",
														monitorValid:true,
														labelAlign	:'top',
														bodyStyle	:'padding:5px',
												        layout		:'column',
												        border		:false,								
														items: [{
														            columnWidth:0.5,
																	defaultType: 'textfield',
														            layout: 'form',
																	border:false,
																	items:[{
																			fieldLabel: 'Id incasare',
																			id:'q-id-incasare',
																			name: 'OLD_ID',
																			anchor: '90%',
																			readOnly:true
																		},{
																			fieldLabel: 'Numar chitanta',
																			id:'q-nr-chitanta',
																			name: 'numar',
																			anchor: '90%',
																			readOnly:true
																		},{
																			fieldLabel: 'Data emiterii',
																			id:'q-data-emiterii',
																			name: 'data_emiterii',
																			anchor: '90%',
																			readOnly:true
																		},{
																			fieldLabel: 'Valoarea',
																			id:'q-valoarea',
																			name: 'valoarea',
																			anchor: '90%',
																			readOnly:true
																		}
																	]
																},{
														            columnWidth:0.5,
																	defaultType: 'textarea',
														            layout: 'form',
																	border:false,
																	items:[new Ext.form.DateField({
																			id			:'q-data-anulare',
																			anchor		:'90%',
												                        	fieldLabel	:'Data',
												                        	name		:'data',
												                        	width		:190,
																			allowBlank	:false,
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i>',	
																			invalidText :'{value} nu este o data valida - Formatul corect este: aaaa-ll-zz',
																			blankText	:'Reguli validare <br /><i>Camp obligatoriu</i><br /><i>Format: aaaa-ll-zz</i>',
																			format		:'Y-m-d'
									            						})]								
																}],
														buttons:[{
															text:'Save and Close',
															tooltip:'Salvati si inchideti',
															formBind:true,
															handler:function(){	
																if (fp_w_user_functionalitati_anulare_incasare.getForm().isValid()) {
																	fp_w_user_functionalitati_anulare_incasare.getForm().submit({
																  		url: "user/functionalitati/anulare_incasare/" + Math.random(),
																		params:{saferequest:true,table:'incasari',cyDep:true},
																		waitTitle: 'Connecting',
																		waitMsg: 'Validating and saving data...',
																		success: function(form, action, o){
																			if (action.result.code == 0) {
																				Ext.MessageBox.alert('Atentie:', 'Eroare la adaugare');
																				fp_w_user_functionalitati_anulare_incasare.getForm().reset();
																			}
																			else 
																				if (action.result.code == 1) {
																					Ext.MessageBox.alert('Mesaj:', 'Adaugare efectuata cu succes!');
																					ds_istoric_plati.reload();
																					fp_w_user_functionalitati_anulare_incasare.getForm().reset();
																					w_user_functionalitati_anulare_incasare.hide();
																				}
																		},
																		failure: function(form, action, o){
																			if (action.failureType == 'server') {
																				Ext.Msg.alert('Warning', 'Cannot save to database!', obj.errors.reason);
																			}
																			else {
																				Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
																			}
																			fp_w_user_functionalitati_anulare_incasare.getForm().reset();
																		}
																	})																	
																}
															}
														}]		
											});																					
											
											w_user_functionalitati_anulare_incasare = new Ext.Window({
												title: 'Anulare incasare',
												width: 610,
												height: 400,
												plain: true,
												layout: 'fit',
												modal: true,
												items: fp_w_user_functionalitati_anulare_incasare,
												closeAction	:'hide',
												loadMask	:{msg:'Loading...'},
												listeners	:{
													'show': function(){
														var selection = grid_istoric_plati.selModel.getSelections();
														
														Ext.getDom('q-id-incasare').value = selection[0].id;
														Ext.getDom('q-valoarea').value = selection[0].json.valoarea;
														Ext.getDom('q-nr-chitanta').value = selection[0].json.nr_chit;
														Ext.getDom('q-data-emiterii').value = selection[0].json.data
													}
												},
									            buttons: [{
												    text	:'Cancel',
													tooltip	:'Renuntati',
												    handler	:function(){
														fp_w_user_functionalitati_anulare_incasare.getForm().reset();
												        w_user_functionalitati_anulare_incasare.hide();
												    }
												}]
											});
																																
											// end fereastra anulare incasare	-------------------------------------------------
											//-----------------------------------------------------------------------------------
										} else {}
										w_user_functionalitati_anulare_incasare.show();																																											
										
									}								
								}
							],
					        bbar: new Ext.PagingToolbar({
								beforePageText:'Pagina&nbsp;',
								afterPageText:'din {0}',
								firstText:'Prima pagina',
								lastText:'Ultima pagina',
								nextText:'Pagina urmatoare',
								prevText:'Pagina precedenta',   
					            pageSize: 20,
					            store: ds_istoric_plati,
					            displayInfo: true,
					            displayMsg: 'Plati {0} - {1} din {2}',
					            emptyMsg: "No records",
								plugins: new Ext.ux.Andrie.pPageSize({
									  beforeText:'',		
								      afterText: '&nbsp;inreg/pagina',
								      sizes: [[5],[10],[25],[50],[100]],
								      comboCfg: {width: 50}
								      })
							})									
						});

		grid_istoric_plati.on('rowdblclick', function(grid, rowIndex, e) {
		    	var selection = grid.selModel.getSelections();
				if(selection[0].json.modalitate == "49"){
					var _idextension = Math.random();
					var w_print = new Ext.Window({
						id: 'window-print-' + Math.random(),
						width: 900,
						height: 480,
						layout: 'fit',
						frame: true,
						loadMask: {
							msg: 'Loading...'
						},
						waitMsg: 'Loading',
						modal: true,
						closable: true,
						closeAction: 'hide',
						defaultType: 'iframepanel',
						items: {
							title: 'Tiparire Chitanta',
							autoLoad: {
								url: 'user/functionalitati/chitanta/' + Math.random(),
								method: 'post',
								params: {
									saferequest: true,
									ID: selection[0].id
								}
							},
							loadMask: true,
							frameConfig: {
								id: 'printIframe-' + _idextension
							}
						},
						buttons: [{
							text	:'Print',
							tooltip	:'Tipariti',
							iconCls	:'b_print_bill_cls',
							handler	:function(){
								Ext.get('printIframe-' + _idextension).print();
							}
						},{
						    text	:'Cancel',
							tooltip	:'Renuntati',
						    handler	:function(){
						        w_print.hide();
						    }
						}]							

					});
					
					//show print window
					w_print.show();
					
				} else {
					Ext.Msg.alert('Warning!', 'Ooops. Incasare cu ordin de plata. Nu puteti vizualiza chitanta.');
				}
		});
		
		function facturi_history(){
			if(grid_user_rapoarte_facturi_emise.selModel.getCount() == 1){
				Ext.MessageBox.confirm('Confirmation','Vizualizare istoric plati. Continuati?', function(btn){
					if (btn == 'yes') {
			
						if (!w_user_rapoarte_facturi_emise_istoric) {
									// istoric facturi grid panel	-----------------------------------------------------
									//-----------------------------------------------------------------------------------	
							
										fp_w_user_rapoarte_facturi_emise_istoric = new Ext.FormPanel({
												labelAlign: 'top',
												width: 600,
										        layout:'column',
										        border:false,								
												items: [{
												            columnWidth:0.3,
												            border: false,
												            items: [{
																xtype		:'fieldset',
																autoHeight	:true,
																defaultType	:'textfield',
																collapsed	:false,
																border		:false,
																anchor		:'90%',
																items:[{
															                fieldLabel	:'Id factura',
																			id			:'x-id-factura',
																			readOnly	:true
															            },{
															                fieldLabel	:'Numar factura',
																			id			:'x-nr-factura',
																			anchor		:'90%',
																			readOnly	:true
															            },{
															                fieldLabel	:'Client',
																			id			:'x-client',
																			anchor		:'90%',
																			readOnly	:true
															            },{
															                fieldLabel	:'Data',
																			id			:'x-data-factura',
																			anchor		:'90%',
																			readOnly	:true
															            },{
															                fieldLabel	:'Valoare',
																			id			:'x-valoare-factura',
																			anchor		:'90%',
																			readOnly	:true
															            }]
															}]
														},{
												            columnWidth:0.7,
												            layout: 'fit',
															border: false,
												            items:[grid_istoric_plati] 					
														}
												]		
									});

									// end istoric facturi grid panel	-------------------------------------------------
									//-----------------------------------------------------------------------------------	
																		
										w_user_rapoarte_facturi_emise_istoric = new Ext.Window({
											id				:'w-user-rapoarte-facturi-emise-istoric' + Math.random(),
											title			:'Istoric plati factura',
											animateTarget	:'b-history',
											width			:900,
											height			:350,
											plain			:true,
											layout			:'fit',
											modal			:true,
											closeAction		:'hide',
											items			:fp_w_user_rapoarte_facturi_emise_istoric,
											loadMask		:{msg:'Loading...'},
											listeners:{
												show: function(){
															var selection = grid_user_rapoarte_facturi_emise.selModel.getSelections();
															
															Ext.getDom('x-id-factura').value = selection[0].id;
															Ext.getDom('x-nr-factura').value = selection[0].json.numar;
															Ext.getDom('x-valoare-factura').value = selection[0].json.valoare;
															Ext.getDom('x-data-factura').value = selection[0].json.data_emiterii;
															Ext.getDom('x-client').value = selection[0].json.client;
															
															ds_istoric_plati.baseParams = {
																saferequest	: true,
																table		: "incasari",
																cyDep		: false,
																FK_FACTURI	: selection[0].id
															};
															
															ds_istoric_plati.load({
																params: {
																	start: 0,
																	limit: 20
																}
															});
												}
											},							
								            buttons: [{
											    text		:'Cancel',
												tooltip		:'Renuntati',
											    handler		:function(){
													fp_w_user_rapoarte_facturi_emise_istoric.getForm().reset();
											        w_user_rapoarte_facturi_emise_istoric.hide();
											    }
											}]
									
										});								

						}else {}
						w_user_rapoarte_facturi_emise_istoric.show();	
					
					}
				});
			} else {
			  	Ext.MessageBox.alert('Warning','Pentru a vizualiza istoric plati, selectati cel putin o inregistrare!');
			}						
		}


/**
 * grid
 * ************************************************************************
 */			
    ds_facturi_emise = new Ext.data.Store({
		id			:'table_ds',
        remoteSort	:true,
		baseParams	:{saferequest:true},			
        proxy: new Ext.data.HttpProxy({
            url: 'common/getBillTable/' + Math.random()		
        }),
        reader: new Ext.data.JsonReader({
            root: 'DS_FACTURI',
            totalProperty: 'totalCount',
            id: 'ID',
            fields: [
                'client', 'numar', 'data_emiterii', 'data_scadentei', 'moneda','valoare','incasat'
            ]
        })
    });	
	
	ds_facturi_emise.setDefaultSort('numar', 'desc');
	ds_facturi_emise.load({params:{start:0, limit:22}});
	
	sm_facturi_emise = new Ext.grid.CheckboxSelectionModel({singleSelect:true});
	
    function rdr_incasat(val){
        if(val > 0){
            return '<span style="color:green;">' + val + '</span>';
        }else if((val <= 0) || val === ''){
            return '<span style="color:red;">' + 'NI' + '</span>';
        }
        return val;
    }		
    cm_facturi_emise = new Ext.grid.ColumnModel([sm_facturi_emise,
			{header: "Nr",dataIndex: 'numar',width:50},
			{header: "Client",dataIndex: 'client'},
			{header: "Data emiterii",dataIndex: 'data_emiterii'},
			{header: "Data scadentei",dataIndex: 'data_scadentei'},
			{header: "Moneda",dataIndex: 'moneda'},
			{header: "Valoare",dataIndex: 'valoare'},
			{header: "Incasat",dataIndex: 'incasat',renderer: rdr_incasat}
	]);
	cm_facturi_emise.defaultSortable = true;			

    grid_user_rapoarte_facturi_emise = new Ext.grid.GridPanel({
		id:'gridfacturiemise' + Math.random(),
        renderTo:'user_rapoarte_facturi_emise',	
		singleSelect:true,			
        height:569,//586,
        anchor:'100%',						
		frame:false,					
        title:'<?=$title?>',
        store: ds_facturi_emise,
        cm: cm_facturi_emise,
		sm: sm_facturi_emise,
        loadMask: true,
        viewConfig: {
            forceFit:true
        },		
        bbar: new Ext.PagingToolbar({
			beforePageText:'Pagina&nbsp;',
			afterPageText:'din {0}',
			firstText:'Prima pagina',
			lastText:'Ultima pagina',
			nextText:'Pagina urmatoare',
			prevText:'Pagina precedenta',   
            pageSize: 22,
            store: ds_facturi_emise,
            displayInfo: true,
            displayMsg: 'Facturi {0} - {1} din {2}',
            emptyMsg: "No records",
			plugins: new Ext.ux.Andrie.pPageSize({
				  beforeText:'',		
			      afterText: '&nbsp;inreg/pagina',
			      comboCfg: {width: 50}
			      })
		}),
        tbar:[{
			id		:'b-cancel',
            text	:'Anuleaza',
            tooltip	:'Anuleaza',
            iconCls	:'b_delete_xml_cls',
			handler	:facturi_check_cancel
        },'-',{
            text:'Plati',
            tooltip:'Istoric plati',
            iconCls:'b_history_cls',
			handler: facturi_history
        }			
		],plugins: new Ext.ux.grid.Search({
					searchText:'Criterii',
					searchTipText:'Introduceti textul dorit...',
					iconCls:'b_search_cls',
					minChars:2,
					autoFocus:true,
					text:'Cauta dupa camp',
					mode:'remote',
					position:'top'
		})					
    });

	/****************************
	 * 
	 * previzualizare factura
	 * @param {Object} grid
	 * @param {Object} rowIndex
	 * @param {Object} e
	 */	
	grid_user_rapoarte_facturi_emise.on('rowdblclick', function(grid, rowIndex, e) {
			
			if(!w_user_rapoarte_facturi_emise_previzualizare){
				var _idextension = Math.random();
		        w_user_rapoarte_facturi_emise_previzualizare = new Ext.Window({
						id			:'w-user-rapoarte-facturi-emise-previzualizare' + Math.random(),
		                width		:900,
						height		:480,
		                layout 		:'fit',
		                frame		:false,
						loadMask	:{msg:'Loading...'},
						waitMsg		:'Loading',
						modal		:true,
						closeAction	:'hide',						
						defaultType :'iframepanel',											
		                items:{ 
							title		:'Vizualizare factura',
							loadMask:{hideOnReady :false,msg:'Loading ...'},
							frameConfig	:{
								id:'previewIframe-' + _idextension
							}	                    
						},
						listeners:{
							show:function(){
								var selection = grid_user_rapoarte_facturi_emise.selModel.getSelections();		
								Ext.get('previewIframe-' + _idextension).load({
									url: 'user/functionalitati/previzualizare/' + Math.random(),
									method:'post',
									params	:{
										saferequest	:true,
										ID			:selection[0].id
									}									
								});
							}
						},
						buttons: [{
							text	:'Print',
							tooltip	:'Tipariti',
							iconCls	:'b_print_bill_cls',
							handler	:function(){
								Ext.get('previewIframe-' + _idextension).print();
							}
						},{
							text	:'PDF',
							tooltip	:'Trimiteti factura in format pdf',
							iconCls	:'b_adobe_pdf_cls',
							handler	:function(){
										var selection = grid_user_rapoarte_facturi_emise.selModel.getSelections();	
										
										Ext.Ajax.request({
										   url: 'user/functionalitati/verificaClientEmail/' + Math.random(),
										   disableCaching:false,
										   params:{
												saferequest	:true,
												ID			:selection[0].id										   	
										   },
										   success: function(response, options) {
												var data = Ext.util.JSON.decode(response.responseText);
												if (data.code == 0){
													Ext.MessageBox.alert('Warning','Acest client nu are introdusa o adresa email');	
												} else if (data.code != ''){
													Ext.MessageBox.confirm('Confirmation','Trimitem factura pdf la adresa '+ data.code +'. Continuati?', function(btn){
														if (btn == 'yes') {
															Ext.Ajax.request({
															   url: 'user/functionalitati/pdf/' + Math.random(),
															   disableCaching:false,
															   params:{
																	saferequest	:true,
																	ID			:selection[0].id										   	
															   },
															   success: function(response, options) {
																	var data = Ext.util.JSON.decode(response.responseText);
																	if (data.code == 1) {	
																			Ext.MessageBox.alert('Mesaj:', 'Trimitere pdf efectuata cu succes!');
																	}else if (data.code == 0){
																			Ext.MessageBox.alert('Eroare:', response.responseText);														
																	}
																},										
																failure: function(form, action, o){
												                            if(action.failureType == 'server'){
												                                Ext.Msg.alert('Warning', 'Cannot send mail!', obj.errors.reason);
												                            }else{
												                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
												                            }
																}
															});																											
														}
													});
												}
											},										
											failure: function(form, action, o){
							                            if(action.failureType == 'server'){
							                                Ext.Msg.alert('Warning', 'Cannot read database!', obj.errors.reason);
							                            }else{
							                                Ext.Msg.alert('Warning!', 'Authentication server is unreachable!');
							                            }
											}
										});												
							}	
						},{
						    text	:'Cancel',
							tooltip	:'Renuntati',
						    handler	:function(){
						        w_user_rapoarte_facturi_emise_previzualizare.hide();
						    }
						}]
		            });
					
			}else {}
			w_user_rapoarte_facturi_emise_previzualizare.show();
	});				


		
});	
</script>